<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <% 
String path = request.getContextPath(); 
// 获得项目完全路径（假设你的项目叫MyApp，那么获得到的地址就是 http://localhost:8080/MyApp/）: 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
<!DOCTYPE html>
<html>
<head>
<base href=" <%=basePath%>"> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="书籍详情">
<meta name="author" content="xwj">
<title>书籍详细信息</title>
<link rel="stylesheet" href="css/user_css/css/bootstrap.min.css" />
  <!-- 仅限本页面使用 -->
         <link rel="stylesheet" href="css/user_css/css/book-detail-style.css" />
         
        <link rel="stylesheet" href="css/user_css/css/font-awesome.min.css" />
        <link href="public_user/style.css" rel="stylesheet">
      
<body>
<!--header start-->
     <%@include file="header.jsp"%>
      <!--header end-->
      <!-- heading-banner-start -->
        <div class="heading-banner">
            <div class="container">
                <div class="row">
                    <div class="col-md-12 col-xs-12">
                        <div class="breadcrumb">
                            <a title="Return to Home" href="public_user/index.jsp">
                                <i class="icon-home"></i>
                            </a>
                            <span class="navigation-page">
                                <span class="navigation-pipe">></span>
                               		书籍详细
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- heading-banner-end -->
        
        
        <!-- 商品信息区域 -->
	<div class="productinfo-area">
		<div class="container">
			<div class="row">
				<div class="col-md-5 col-xs-12 col-sm-5">
					<div class="picture-tab">
						<div class="tab-content"><div id="pic0" class="tab-pane fade in active"><div class="single-product">
						<div class="single-product-img">
						<a href=""> 
						<img id="detail_img" src="images/books_pic/ddb1.jpg"></a></div></div></div></div>
					</div>
				</div>
				<div class="col-md-7 col-xs-12 col-sm-7">
					<div class="productinfo-details">
					<h5 class="product-title" id="detail_bname">可爱的身体1</h5>
					<h6 class="product-author" id="detail_author">作者：[日] 七尾纯 小林</h6>
					<div class="price-box">
					<span class="price" id="detail_price">¥78</span> 
					<span class="old-price" id="detail_orgprice">¥98</span></div>
					<div class="short-description">
					<h4>简介：</h4><p id="detail_desc">&nbsp;&nbsp;&nbsp;&nbsp;可爱的身体，可爱的身体</p></div>
					<div class="add-cart">
					<p class="quantity cart-plus-minus"><label>数量</label> 
					<input type="number" name="snum" value="1" min="1" max="11"/>
					<input type="hidden" name="bid">
					</p><div class="shop-add-cart">
					<button onclick="addShopCart(0)">加入购物车</button>
					<button onclick="addShopCart(1)">立即购买</button></div></div></div>
				</div>
			</div>
		</div>
	</div>
        
        	<!-- 评论区域（推荐区域，商品详情，评论部分） -->
	<div class="comments-area">
		<div class="container">
			<div class="row">
				<!-- 推荐区域 -->
				<div class="col-md-3 col-xs-12 hidden-xs">
				</div>
				<!-- 商品详情、评论 -->
				<div class="col-md-9 col-xs-12 col-sm-12">
					<!-- 商品详情 -->
					<div class="product-detail"><h4>商品详情</h4>
					<div class="col-md-4 col-xs-4 col-sm-4" id="detail">
					<p id="detail_press">出版社：人民出版社</p>
					<p id="detail_pressdate">出版时间：2015年6月</p>
					<p id="detail_category">所属分类：童书</p></div>
					<div class="col-md-4 col-xs-4 col-sm-4">
					<p id="detail_flag">是否上架：是</p>
					<p id="detail_btime">上架时间：2017年06月12日</p></div>
					<div class="col-md-4 col-xs-4 col-sm-4">
					<p id="detail_number">库存量：122本</p>
					<p>国际标准书号ISBN：56415678943216</p></div></div>
					<!-- 评论区域 -->
					
				</div>
			</div>
		</div>
	</div>
        
        
        
        
        
        
        
         <!--footer start-->
   <%@include file="footer.jsp"%>
   <!--footer end-->
   <script src="css/user_css/js/vendor/jquery-1.12.0.min.js"></script>
        <!-- bootstrap js -->
        <script src="css/user_css/js/bootstrap.min.js"></script>
        <!-- owl.carousel js -->
        <script src="css/user_css/js/owl.carousel.min.js"></script>
        <!-- meanmenu js -->
        <script src="css/user_css/js/jquery.meanmenu.js"></script>
        <!-- countdown js -->
        <script src="css/user_css/js/countdown.js"></script>
        <!-- jquery.nivo.slider.pack js -->
        <script src="css/user_css/js/jquery.nivo.slider.pack.js"></script>
        <!-- jquery-ui.min.js -->
        <script src="css/user_css/js/jquery-ui.min.js"></script>
        <!-- wow js -->
        <script src="css/user_css/js/wow.min.js"></script>
        <!-- plugins js -->
        <script src="css/user_css/js/plugins.js"></script>
        <!-- main js -->
        <script src="css/user_css/js/main.js"></script>
        <script>
        var id;				//图书id
       	//var bimg=$("#detail_img");
		var bname=$("#detail_bname"); 
		var author=$("#detail_author");
		 var price=$("#detail_price");
		var orgprice=$("#detail_orgprice");
		 var desc=$("#detail_desc");
		 var press=$("#detail_press");
		 var pressdate=$("#detail_pressdate");
		 
		var category=$("#detail_category");
		var bflag=$("#detail_flag");
		var btime=$("#detail_btime");
		var nums=$("#detail_number"); 
		/* 页面初始化加载配置   */
		var this_bid;
		$(document).ready(function() {
			/* 获取传过来的图书id  */
			var h=window.location.href;
			var a=h.split("?id=");
			id=a[1];
			init();
			getOneBook();
			});
        //页面初始化设置
        function init(){
        	bname.html("");
    		author.html("");
    		 price.html("");
    		 orgprice.html("");
    		 desc.html("");
    		 press.html("");
    		 pressdate.html("");
    		 category.html("");
    		 bflag.html("");
    		 btime.html("");
    		 nums.html("");
		
        }
        //获得单个书籍
        function getOneBook(){
         	$.ajax({
     			url : "booksMsg/getOneBookById.do", // 请求地址
     			type : "POST", // 请求类型
     			async : "true", // 是否异步方式
     			data : {"bid":id},
     			dataType : "json", // 返回数据格式
     			success : function(data) {
     				if (data.res>0) {
     					$.each(data.list,function(index, element) {
     						 $('#detail_img').attr('src', element.bpicurl); 
     						 bname.html(element.bname);
     			    		author.html(element.bauthor);
     			    		price.html("￥"+element.bprice);
     			    		orgprice.html("￥"+element.borgprice);
     			    		desc.html(element.bdesc);
     			    		press.html("出版社："+element.bpress);
     			    		pressdate.html("出版时间："+element.bpressdate);
     			    		category.html("类别名："+element.category.cname);
     			    		bflag.html("上架状态："+"是");
     			    		btime.html("上架时间："+element.btime);
     			    		nums.html("库存量："+element.bnumber); 
     			    		this_bid=element.bid;
     			    		
     					});
     					
     						
     	           
     				}
     			}
     		});
        }
        
        //添加购物车
        function addShopCart(flag){
        	//flag=0是添加购物车，1是加入购物车并立即购买
        	$("input[name='bid']").val(this_bid);
        	var snum=$("input[name='snum']").val();
        	var bid=$("input[name='bid']").val();
        
   			$.ajax({
    			url : "shopCartMsg/addNewCart.do", // 请求地址
    			type : "POST", // 请求类型
    			async : "true", // 是否异步方式
    			data : {"bid":bid,
    				"snum":snum
    				},
    			dataType : "json", // 返回数据格式
    			success : function(data) {
    				if(data.res==0){
    					alert("请先登录！");
    				}
    				if (data.res>0) {
    					if(flag==0){
    						alert("添加成功");
    						//更新头部购物车
    	 					getMyCarInfo();
    					}else{
    						//立即购买添加信息并跳转购物车页面
    						window.location.href="public_user/my_cart.jsp";
    					}
    				
    					
    				}
    			}
    		});
       }
        </script>
</body>
</html>